package training.bms.presentation;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import training.bms.business.Blog;
import training.bms.business.BlogController;
import training.bms.business.BlogSearchOptions;
import training.bms.business.Post;
import training.bms.business.PostController;
import training.bms.business.PostSearchOptions;
import training.framework.business.AbstractEntityController;
import training.framework.presentation.AbstractSearchEntity;

@ManagedBean
@SessionScoped
public class SearchPost extends AbstractSearchEntity<Integer, Post, PostSearchOptions, PostPanel> {

	private PostController controller;
	private static final int MAX_RESULTS = 10;
	private List<Blog> blogs;
	
	public SearchPost(){
		super(PostSearchOptions.class,"searchPost", "Post not found",MAX_RESULTS);
		this.controller = new PostController();
	}

	@Override
	protected AbstractEntityController<Integer, Post, PostSearchOptions> getController() {
		return controller;
	}
	
	@Override
	public String initialize() throws InstantiationException, IllegalAccessException{
		String initializeOutCome = super.initialize();
		blogs = searchBlogs();
		return initializeOutCome;
	}
	
	public String initialize2() throws InstantiationException, IllegalAccessException{
		blogs = searchBlogs();
		return "searchPost";
	}

	private List<Blog> searchBlogs() {
		BlogSearchOptions options = new BlogSearchOptions();
		BlogController controller = new BlogController();
		return controller.searchEntity(options);
	}

	public List<Blog> getBlogs() {
		return blogs;
	}

	public void setBlogs(List<Blog> blogs) {
		this.blogs = blogs;
	}

}
